package me.jessyan.mvparms.demo.di.module.account;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.widget.CustomPopupWindow;

import javax.inject.Named;

import dagger.Module;
import dagger.Provides;

import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.mvp.contract.account.AccountManageContract;
import me.jessyan.mvparms.demo.mvp.model.account.AccountManageModel;
import me.jessyan.mvparms.demo.utils.PerfectClickListener;


@Module
public class AccountManageModule {
    private AccountManageContract.View view;

    /**
     * 构建AccountManageModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public AccountManageModule(AccountManageContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    AccountManageContract.View provideAccountManageView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    AccountManageContract.Model provideAccountManageModel(AccountManageModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    @Named("unBindPop")
    CustomPopupWindow unBindPop(){
        //确定删除这个过期礼品?
        View content = LayoutInflater.from(view.getActivity())
                .inflate(R.layout.pop_frag_mine_loginout,null);
        CustomPopupWindow popupWindow = CustomPopupWindow.builder()
                .isFocus(true)
                .isOutsideTouch(true)
                .isWrap(true)
                .contentView(content)
                .customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {
                        TextView titleTv= contentView.findViewById(R.id.pop_title_tv);
                        TextView startTv = contentView.findViewById(R.id.pop_start_tv);
                        TextView endTv = contentView.findViewById(R.id.pop_end_tv);
                        titleTv.setText("确定要解绑微信？");
                        startTv.setText("解绑");

                       startTv.setOnClickListener(new PerfectClickListener() {

                            @Override
                            protected void onNoDoubleClick(View v) {

                                view.dismissPop();
                                view.popBackSureBind();
                            }
                        });
                       endTv.setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.dismissPop();
                            }
                        });

                    }
                }).build();
        //PopupWindow全屏显示
        popupWindow.setClippingEnabled(false);
        return popupWindow;
    }

}